<template>
	<view class="wrap" :class='APPTheme'>
		<view class="content">
			<view class="title">注册</view>
			<view class="input-title">登录名：</view>
			<input class="u-border-bottom" type="text" v-model="register.loginName" placeholder="请输入登录名" focus/>
			<view class="input-title">用户名：</view>
			<input class="u-border-bottom" type="text" v-model="register.name" placeholder="请输入用户名" focus/>
			<view class="input-title">手机号码：</view>
			<input class="u-border-bottom" type="number" v-model="register.phone" placeholder="请输入手机号" focus/>
			<view class="input-title">密码：</view>
			<input class="u-border-bottom" type="password" v-model="register.password" placeholder="请输入密码" focus/>
			<view class="input-title">确认密码：</view>
			<input class="u-border-bottom" type="password" v-model="register.agingPas" placeholder="请输入密码" focus/>
			<view class="input-title flex">组织：<uni-tag text="选取" size="small" @click="selectOrg"></uni-tag></view>
			<view><uni-tag :text="register.orgName" type="warning" inverted circle></uni-tag></view>
			<wButton text="立即注册" :rotate="isRotate"  bgColor="linear-gradient(to right, rgba(10,177,87,0.7), rgba(50,135,200,0.6))" @click.native="submit()" class="getCaptcha"></wButton>
			<view class="alternative">
				<view class="password" @click="passwordLogin">密码登录</view>
				<view class="issue" @click="seaveFn">验证码登录</view>
			</view>
		</view>
	</view>
</template>

<script>
let that
import {mapGetters,mapActions} from 'vuex'
import wButton from '@/components/watch-login/watch-button.vue' //button
export default {
	components:{
		wButton
	},
	data() {
		return {
			user_agreement:false,

			register:{
				loginName: '',//登录名
				name:'',//用户名
				password:'',//密码
				agingPas:'',//确认密码
				phone:'',//手机号
				orgId:'',//组织id
				orgName:'',
			},
			isRotate: false, //是否加载旋转
		}
	},
	computed: {
		...mapGetters(['APPTheme','userInfo','api']),
	},
	onLoad() {
		that=this
		uni.$on('register_selectOrg',res=>{
			console.log(res);
			that.register.orgId=res.departmentsList[0].id
			that.register.orgName=res.departmentsList[0].orgName
		})
	},
	methods: {
		submit() {
			//验证表单
			let result= that.validateForm()
			if(result.code==200) {
				that.GLOBAL.doPost(that.api.GLOBAL_admin_register,that.register).then(res=>{
					if(res.data&&res.data.flag){
						uni.showToast({
							title: res.data.msg,
							icon:"none",
							success() {
								uni.navigateBack({
									delta:1 
								});
							}
						});
						
					}else{
						uni.showToast({
							title: res.data.msg,
							icon:"none"
						});
					}
				})
			}else{
				uni.showToast({
					title: result.msg,
					icon:"none"
				});
				
			}
		},
		//验证表单
		validateForm(){
			if(that.register.loginName&&that.register.name&&that.register.password&&that.register.agingPas&&that.register.phone&&that.register.orgId){
				if(that.register.password!=that.register.agingPas){
					return{code:300,msg:'两次密码不一致'}
				}
				if(that.register.password.length<6){
					return{code:300,msg:'密码长度最少6位'}
				}
				if(!that.$lizhao.test.mobile(that.register.phone)){
					console.log(that.$lizhao.test.mobile(that.register.phone));
					return{code:300,msg:'手机格式不正确'}
				}
				return{code:200,msg:'验证通过'}
			}else{
				return{code:300,msg:'请填写完整'}
			}
		},
		//密码登陆
		passwordLogin(){
			uni.reLaunch({
				url: '/pages/template/login/passwordLogin',
			});
		},
		//验证码登录
		seaveFn(){
			uni.reLaunch({
				url: '/pages/template/login/login',
			});
		},
		//选取组织
		selectOrg(){
			uni.navigateTo({
				url: '../selectOrg/selectOrg?title=选取组织',
			});
		}
	}
};
</script>

<style lang="scss" scoped>
@import '../login/login.scss';
.flex{
	display: flex;justify-content: space-between;
}
</style>
